/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jigdo.data.template;

import jigdo.data.template.*;
import jigdo.data.template.section.TemplateDATASection;

/**
 * Convenience class to iterate through the data sections of a jigdo template
 * @author John R Sohn
 */
public class TemplateDataIterator implements java.util.Iterator {
    
    
    TemplateDataIterator(JigdoTemplate src)
    {
        source =src;
        
    }
    public void remove()
    {
        
    }
    
    int currPos =0;
    int nextpos =0;
    JigdoTemplate source;
    
    public boolean hasNext()
    {
        if (nextpos==-1)
        {
            return false;
        }
        for (int x=nextpos; x < source.TemplateSections.size(); x++)
        {
            nextpos =x;
            
            if (source.TemplateSections.get(x).SectionType == TemplateType.DATA)
            {
                return true;
            }
            
        }
        
        nextpos=-1;
        
        return false;
    }
    
    public TemplateDATASection next() throws java.util.NoSuchElementException
    {
        if (!hasNext())
        {
            throw new java.util.NoSuchElementException();
        }
        else 
        {
           
           TemplateDATASection data =(TemplateDATASection)source.TemplateSections.get(nextpos);
           nextpos++;
           return data;
        }
    }
    
}
